PASO 7: Podemos ver a nuestro jugador en el escenario ahora, pero necesitamos devolver el sprite de add_player() para poder usar el sprite en nuestra función main() .
La declaración de retorno pasa una variable de una función de regreso a donde se llama la función.
Haga clic en LÓGICA. Ir a y arrastre Return Statement a la última línea de add_player() .
Cambie la variable que se devuelve de my_var a player . ¡Asegúrese de que esta declaración de devolución esté sangrada!
To navigate the page using the TAB key, first press ESC to exit the code editor.
def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def add_player():
""" Adds a player to the stage for the user to control """
player = codesters.Sprite("player1")
player.go_to(0, -155)
def main():
""" Sets up the program and calls other functions """
set_stage()
player = add_player()
main()
t = codesters.Teacher()
defs = t.find_block("def")
returns = t.find_text("return")
def get_above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
try:
tval1 = returns[0][1].replace(' ','').lower()
tval1_line_num = returns[0][0]
tval1_indent = t.get_indent_at_line(tval1_line_num)
except:
tval1 = "DNE"
tval1_indent = "DNE"
tval1_line_num = "DNE"
try:
above_def, distance = get_above_def(tval1_line_num, defs)
except:
above_def = "DNE"
distance = "DNE"
t1 = TestObjective()
t1.add_success("player" in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add Return Statement in add_player()?")
t1.add_failure("my_var" in tval1, "Did you change my_var to player?")
t1.add_failure("player" not in tval1, "Did you rename the return variable to player?")
t2 = TestObjective()
t2.add_success(tval1_indent == 4, "Great job!")
t2.add_failure(tval1_indent < 4 or tval1_indent > 4, "Did you indent Return Statement once inside add_player()?")
t3 = TestObjective()
t3.add_success("add_player" in above_def and distance > 2, "Great job!")
t3.add_failure("add_player" not in above_def, "Did you put the Return Statement in the add_player() function?")
t3.add_failure("add_player" in above_def and distance < 3, "Oops, make sure the Return Statement is the last line in add_player()!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.